package com.example.signsystem.controller;

import cn.hutool.core.bean.BeanUtil;
import com.example.signsystem.entity.dto.AttendanceDTO;
import com.example.signsystem.entity.vo.AttendanceCount;
import com.example.signsystem.entity.po.StudentsPO;
import com.example.signsystem.entity.vo.AttendanceVO;
import com.example.signsystem.service.IAttendanceService;
import com.example.signsystem.service.IStudentsService;
import com.example.signsystem.service.ISignListService;
import com.qcby.framework.common.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;

@RestController
@RequestMapping("/sign-system")
public class SignController {


    @Autowired
    private ISignListService signListService;

    @Resource
    private IStudentsService studentsService;

    @Resource
    private IAttendanceService attendanceService;

    @GetMapping("/sign")
    public Result<Boolean> sign(@RequestHeader(value = "phone") Long phone) throws ParseException {
        return Result.getSuccessResult(signListService.signIn(phone));
    }


    @GetMapping("/sl-not-checked-in-today")
    public Result<AttendanceCount> notSignIn(){
        return Result.getSuccessResult(signListService.todayStudents());
    }


    @GetMapping("/sign-up")
    public Result<Boolean> notSignIn(StudentsPO studentsPO){
        studentsService.getBaseMapper().insert(studentsPO);
        return Result.getSuccessResult(Boolean.TRUE);
    }


    @GetMapping("/get-attendance-status")
    public Result<AttendanceVO> getAttendanceStatus(String name){
        AttendanceDTO attendanceStatus = attendanceService.getAttendanceStatus(name);
        AttendanceVO attendanceVO = BeanUtil.copyProperties(attendanceStatus, AttendanceVO.class);
        return Result.getSuccessResult(attendanceVO);
    }
}
